//
// Created by 喵喵乐 on 2023/4/9.
//

#ifndef CMAKECXX_PWRAP_H
#define CMAKECXX_PWRAP_H

#include <iostream>
#include <cstddef>

using namespace std;

template<class T, int sz = 1>
class PWrap {
    T *ptr;
public:
    PWrap() : ptr(new T[sz]) {
        cout << "PWrap constructor " << endl;
    }

    ~PWrap() {
        delete[] ptr;
        cout << "Pwrap destructor " << endl;
    }

    T &operator[](int i) {
        if (i >= 0 && i < sz) return ptr[i];
        throw 3;
    }
};

#endif //CMAKECXX_PWRAP_H
